/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/service/{{entities@SQL}}Service.java.hbs
 */
package cn.ibizlab.core.ad.service;

import java.util.*;

import org.springframework.data.domain.Page;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.ibizlab.util.security.SpringContextHolder;
import cn.ibizlab.util.domain.ImportResult;
import cn.ibizlab.core.ad.domain.SysOrganization;
import cn.ibizlab.core.ad.filter.SysOrganizationSearchContext;
import cn.ibizlab.core.ad.domain.SysDepartment;
import cn.ibizlab.core.ad.domain.SysPerson;
import cn.ibizlab.core.ad.domain.SysOrganizationalRole;
import cn.ibizlab.core.ad.domain.SysOrganizationalUnit;

/**
 * 组织机构服务接口[SysOrganizationService]
 *
 * @author generator
 */
public interface SysOrganizationService extends IService<SysOrganization> {

    /**
     * 获取当前Service
     *
     * @return
     */
    default SysOrganizationService getSelf() {
        return SpringContextHolder.getBean(this.getClass());
    }

    /**
     * 获取
     * @param et
     * @return
     */
    SysOrganization get(SysOrganization et);
    /**
     * 获取
     * @param key
     * @return
     */
    default SysOrganization get(String key) {
        return getSelf().get(new SysOrganization().setId(key));
    }
    /**
     * id集合获取
     * @param ids
     * @return
     */
    default List<SysOrganization> getByIds(Collection<String> ids) {
        List<SysOrganization> entities =new ArrayList<>();
        ids.forEach(key -> entities.add(new SysOrganization().setId(key)));
        return getSelf().getByEntities(entities);
    }
    /**
     * 对象集合获取
     * @param entities
     * @return
     */
    List<SysOrganization> getByEntities(List<SysOrganization> entities);

    /**
     * 草稿
     * @param et
     * @return
     */
    SysOrganization getDraft(SysOrganization et);

    /**
     * checkKey
     * @param et
     * @return
     */
    Integer checkKey(SysOrganization et);

    /**
     * 创建
     * @param et
     * @return
     */
    boolean create(SysOrganization et);
    /**
     * 批量创建
     * @param list
     * @return
     */
    boolean createBatch(List<SysOrganization> list);

    /**
     * 更新
     * @param et
     * @return
     */
    boolean update(SysOrganization et);
    /**
     * 批量更新
     * @param list
     * @return
     */
    boolean updateBatch(List<SysOrganization> list);

    /**
     * 保存
     * @param et
     * @return
     */
    @Override
    boolean save(SysOrganization et);
    /**
     * 批量保存
     * @param list
     * @return
     */
    boolean saveBatch(List<SysOrganization> list);

    /**
     * 主键删除
     * @param key
     * @return
     */
    default boolean remove(String key) {
        return getSelf().remove(new SysOrganization().setId(key));
    }
    /**
     * 根据keys批量删除
     * @param keys
     * @return
     */
    default boolean remove(List<String> keys) {
        return removeBatch(keys);
    }
    /**
     * 根据对象删除
     * @param et
     * @return
     */
    boolean remove(SysOrganization et);

    /**
     * 批量删除
     * @param ids
     * @return
     */
    default boolean removeBatch(Collection<String> ids) {
        List<SysOrganization> entities =new ArrayList<>();
        ids.forEach(key -> entities.add(new SysOrganization().setId(key)));
        return getSelf().removeByEntities(entities);
    }

    /**
     * 批量删除对象
     * @param entities
     * @return
     */
    boolean removeByEntities(List<SysOrganization> entities);

    default ImportResult importData(String config, Boolean ignoreError, List<SysOrganization> list) {
        ImportResult rt = new ImportResult().setTotal(list.size());
        for(int i=0;i<list.size();i++) {
            SysOrganization et=list.get(i);
            try {
                this.getSelf().save(et);
                rt.setSuccess(rt.getSuccess()+1);
            }catch (Exception ex){
                rt.addItem(i+1,et.getOrganizationName(),ex.getMessage());
                if(!ignoreError)
                    break;
            }
        }
        return rt;
    }

    /**
     * All
     * 
     * @param dto
     * @return
     */
    default List<SysOrganization> all(SysOrganization dto) {
        return new ArrayList<>();
    }

    /**
     * Cache_evict
     * 
     * @param dto
     * @return
     */
    default SysOrganization cacheEvict(SysOrganization dto) {
        return dto;
    }

    /**
     * FindOrganizationId
     * 
     * @param dto
     * @return
     */
    default String findOrganizationId(SysOrganization dto) {
        return null;
    }

    /**
     * Items
     * 根据传入的id 查询 id对应单位清单，不传入id时自动取当前用户可见清单
     * @param dto
     * @return
     */
    default List<SysOrganization> items(SysOrganization dto) {
        return new ArrayList<>();
    }

    /**
     * Options
     * 
     * @param dto
     * @return
     */
    default List<SysOrganization> options(SysOrganization dto) {
        return new ArrayList<>();
    }

    /**
     * ParentIds
     * 
     * @param dto
     * @return
     */
    default List<String> parentIds(SysOrganization dto) {
        return new ArrayList<>();
    }

    /**
     * SubIds
     * 
     * @param dto
     * @return
     */
    default List<String> subIds(SysOrganization dto) {
        return new ArrayList<>();
    }

    /**
     * TreeList
     * 
     * @param dto
     * @return
     */
    default List<SysOrganization> treeList(SysOrganization dto) {
        return new ArrayList<>();
    }

    /**
     * searchDefault
     * 
     * @param context
     * @return
     */
    Page<SysOrganization> searchDefault(SysOrganizationSearchContext context);
    /**
     * listDefault
     * 
     * @param context
     * @return
     */
    List<SysOrganization> listDefault(SysOrganizationSearchContext context);

    /**
     * searchMaintenance
     * 
     * @param context
     * @return
     */
    Page<SysOrganization> searchMaintenance(SysOrganizationSearchContext context);
    /**
     * listMaintenance
     * 
     * @param context
     * @return
     */
    List<SysOrganization> listMaintenance(SysOrganizationSearchContext context);

    /**
     * searchMyOrg
     * 
     * @param context
     * @return
     */
    Page<SysOrganization> searchMyOrg(SysOrganizationSearchContext context);
    /**
     * listMyOrg
     * 
     * @param context
     * @return
     */
    List<SysOrganization> listMyOrg(SysOrganizationSearchContext context);

    /**
     * searchNav
     * 
     * @param context
     * @return
     */
    Page<SysOrganization> searchNav(SysOrganizationSearchContext context);
    /**
     * listNav
     * 
     * @param context
     * @return
     */
    List<SysOrganization> listNav(SysOrganizationSearchContext context);

    /**
     * searchParentOrg
     * 自定义代码：实现过滤本级和下级单位
     * @param context
     * @return
     */
    Page<SysOrganization> searchParentOrg(SysOrganizationSearchContext context);
    /**
     * listParentOrg
     * 自定义代码：实现过滤本级和下级单位
     * @param context
     * @return
     */
    List<SysOrganization> listParentOrg(SysOrganizationSearchContext context);

    /**
     * 创建实体对象
     * @return
     */
    default SysOrganization getEntity() {
        return new SysOrganization();
    }
    /**
     * 创建搜索对象
     * @return
     */
    default SysOrganizationSearchContext getSearchContext() {
        return new SysOrganizationSearchContext();
    }
    /**
     * selectRelByParentId
     * @param parentIds
     * @return
     */
    List<SysOrganization> findByParentId(List<String> parentIds);
    default List<SysOrganization> findByParentId(String parentId) {
        return findByParentId(Arrays.asList(parentId));
    }
    /**
     * removeRelByParentId
     * @param parentId
     * @return
     */
    boolean removeByParentId(String parentId);
    /**
     * resetRelByParentId
     * @param parentId
     * @return
     */
    boolean resetByParentId(String parentId);
    /**
     * saveRelByParent
     * @param sysOrganization
     * @param list
     * @return
     */
    boolean saveByParent(SysOrganization sysOrganization,List<SysOrganization> list);
    /**
     * saveRelByParentId
     * @param parentId
     * @param list
     * @return
     */
    default boolean saveByParentId(String parentId,List<SysOrganization> list) {
        return getSelf().saveByParent(new SysOrganization().setId(parentId),list);
    }

    default List<SysDepartment> getDepartments(SysOrganization et) {
        return new ArrayList<>();
    }


    /**
     * 自定义查询SQL
     * @param sql  select * from table where id =#{et.param}
     * @param param 参数列表  param.put("param","1");
     * @return
     */
    List<JSONObject> select(String sql, Map<String,Object> param);

    /**
     * 自定义SQL
     * @param sql  update table  set name ='test' where id =#{et.param}
     * @param param 参数列表  param.put("param","1");
     * @return
     */
    boolean execute(String sql, Map<String,Object> param);

}